﻿#region COPYRIGHT
//--------------------------------------------------------------------------------
// <copyright file="ScrollBar.cs" company="starLiGHT Entertainment Studios">
//    Copyright (c) 2011 
//       Roland Rosenkranz (Glatzemann@email.de)
// </copyright>
// <license>
//   This file is part of starLiGHT.GUI.
//
//   It is released under the Microsoft Public License (Ms-PL).
//
//   You should have received a copy of the Microsoft Public License
//   along with starLiGHT.GUI. If not, see http://sle.codeplex.com/license.
//    
//   ADDITIONAL (commercial) LICENSES for starLiGHT.GUI are available on request.
// </license>
// <version>
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev::                       $:  Revision of last commit *
// * $Author::                    $:  Author of last commit   *
// * $Date::                      $:  Date of last commit     *
// ************************************************************
// </version>
//--------------------------------------------------------------------------------
#endregion

namespace starLiGHT.GUI.Widgets
{
#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
#endregion

    public abstract class ScrollBar : Widget
    {
        #region Private Members
        private int minimum;
        private int maximum;
        private int largeChange;
        private int smallChange;
        private int val;
        #endregion

        #region Constructors
        public ScrollBar(GuiManager manager, string name)
            : base(manager, name)
        {
            this.Init();
        }

        public ScrollBar(GuiManager manager, string name, string layout)
            : base(manager, name, layout)
        {
            this.Init();
        }

        #endregion

        #region Events
        public event EventHandler ValueChanged;
        #endregion

        public int Maximum
        {
            get
            {
                return this.maximum;
            }

            set
            {
                this.maximum = value;
                this.val = this.val < this.minimum ? this.minimum : this.val > this.maximum ? this.maximum : this.val;
            }
        }

        public int Minimum
        {
            get
            {
                return this.minimum;
            }

            set
            {
                this.minimum = value;
                this.val = this.val < this.minimum ? this.minimum : this.val > this.maximum ? this.maximum : this.val;
            }
        }

        public int LargeChange
        {
            get
            {
                return this.largeChange;
            }

            set
            {
                this.largeChange = value;
            }
        }

        public int SmallChange
        {
            get
            {
                return this.smallChange;
            }

            set
            {
                this.smallChange = value;
            }
        }

        public int Value
        {
            get
            {
                return this.val;
            }

            set
            {
                int before = this.val;
                this.val = value < this.minimum ? this.minimum : value > this.maximum ? this.maximum : value;

                if (this.val != before)
                {
                    this.OnValueChanged(this, EventArgs.Empty);
                }
            }
        }

        public virtual void OnValueChanged(object sender, System.EventArgs e)
        {
            if (this.ValueChanged != null)
            {
                this.ValueChanged(sender, e);
            }
        }

        private void Init()
        {
            this.minimum = 0;
            this.maximum = 100;
            this.val = 0;
            this.largeChange = 10;
            this.smallChange = 1;
        }
    }
}
